package com.ruoyi.web.controller.app.service;

import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.framework.web.exception.base.XException;
import com.ruoyi.sj.domain.Feedback;
import com.ruoyi.sj.mapper.FeedbackMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * @ClassName AppFeedBackService
 * @Description TODO
 * @Author tyc@yanyu
 * @Date 2018/12/12 0012 18:27
 **/
@Service
public class AppFeedBackService {
    @Autowired
    private FeedbackMapper feedbackMapper;

    public Object addFeedBack(Map<String, String> map) {
        if (StringUtils.isBlank(map.get("memberId"))||"null".equals(map.get("memberId"))){
                throw  new XException("用户id不能为空");
        }
        if (StringUtils.isBlank(map.get("content"))||"null".equals(map.get("content"))){
                throw new XException("反馈内容不能为空");
        }
        Feedback feedback = new Feedback();
        feedback.setContent(map.get("content"));
        feedback.setMemberId(Long.valueOf(map.get("memberId")));
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        feedback.setCreateDate(sdf.format(new Date()));
        feedback.setStatus(1);
        return feedbackMapper.insertFeedback(feedback);
    }

    public int changeStatus(String id) {
        if (StringUtils.isBlank(id)){
            throw new XException("问题id不能为空");
        }
        return feedbackMapper.changeStatus(id);
    }

    public List<Feedback> queryListById(String memberId) {
        if (StringUtils.isBlank(memberId)){
            throw new XException("用户id不能为空");
        }
        Feedback feedback = new Feedback();
        feedback.setMemberId(Long.valueOf(memberId));
        return feedbackMapper.selectFeedbackList(feedback);
    }

    public int resolved(String id) {
        if (StringUtils.isBlank(id)){
            throw new XException("问题id不能为空");
        }
        return feedbackMapper.resolved(id);
    }
}
